/***
 *
 * 读取文件夹 ， 通过文件夹名称 自动注册组件
 *
 * @type {Record<string, () => Promise<string extends keyof KnownAsTypeMap ? KnownAsTypeMap[string] : unknown>>}
 */

const components= import.meta.glob('./*/index.vue',{eager:true})

export const useGlobalComponent = (app) => {

    const componentsData = Object.keys(components).map(key => {
        const template = components[key].default
        const nameData = key.split('/')
        return { name: nameData.length ? nameData[1] : null, template }
    })

    componentsData.forEach((item) => {
        if(item.name){
            app.component(item.name, item.template)
        }else{
            console.error("全局组件注册失败", item)
        }
    })

    return app
}